//
//  UIButton+Extented.swift
//  SecondWB
//
//  Created by 赖建伟 on 16/11/26.
//  Copyright © 2016年 Itheima. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(normalImage:String,backGroundImage:String,isImageHighlight: Bool = true,isbgImageHighlight: Bool = true) {
        self.init()
        
        
        setImage(UIImage.init(named: normalImage), for: UIControlState.normal)
        if isImageHighlight {
            setImage(UIImage.init(named: "\(normalImage)_highlighted"), for: UIControlState.highlighted)
        }
        
        
        
        setBackgroundImage(UIImage.init(named: backGroundImage), for: UIControlState.normal)
        if isbgImageHighlight {
            setBackgroundImage(UIImage.init(named: "\(backGroundImage)_highlighted"), for: UIControlState.highlighted)
            
        }

        
    }
    
    convenience init(title: String?,titleColor: UIColor?,titleFont: CGFloat?,normalImage:String?,backGroundImage:String?,corner: CGFloat?) {
        
        self.init()
        
        setTitle(title, for: UIControlState.normal)
        setTitleColor(titleColor, for: UIControlState.normal)
        if let titleFont = titleFont {
            
            titleLabel?.font = UIFont.systemFont(ofSize: titleFont)
        }
        
        if let corner = corner {
            layer.cornerRadius = corner
        }
        
//        self.init(normalImage: normalImage, backGroundImage: backGroundImage, isImageHighlight: isImageHighlight, isbgImageHighlight: isbgImageHighlight)
        if let normalImage = normalImage {
            setImage(UIImage.init(named: normalImage), for: UIControlState.normal)
        
        }
        
        if let backGroundImage = backGroundImage {
            setBackgroundImage(UIImage.init(named: backGroundImage), for: UIControlState.normal)
            
        }
        
    }
    
    
}
